//
//  PersonalHomeHeaderView.m
//  Btpin
//
//  Created by Vic on 2019/3/15.
//  Copyright © 2019 Vic. All rights reserved.
//




#import "PersonalHomeHeaderView.h"
#import "NewsCarouselView.h"

@interface PersonalHomeHeaderView () <NewsCarouselViewDelegate>
{
    
}
@end

@implementation PersonalHomeHeaderView

- (instancetype)initWithFrame:(CGRect)frame Target:(id)target {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
        self.delegate = target;
    }
    return self;
}
- (void)initUI {
    PSCarouselView *carouselView = [[PSCarouselView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HomeBannerHeight) images:@[@"home_banner_bg", @"home_banner_bg2", @"home_banner_bg3"] space:0 bgImage:@"home_banner_bg"];
    [self addSubview:carouselView];
//    __weak typeof(self) weakSelf = self;
//    carouselView.tapImage = ^(BannerModel *model) {
    carouselView.tapImage = ^ {
        NSLog(@"轮播图Tap");
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(personalHomeHeaderViewBannerCarouselTap:)]) {
            [self.delegate personalHomeHeaderViewBannerCarouselTap:nil];
        }
    };
    
    
    UIImageView *inviteImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(20*Scale, EndY(carouselView), WIDTH-20*Scale, 125*Scale) imageName:@"home_invite_bg"];
    inviteImgView.userInteractionEnabled = YES;
    [self addSubview:inviteImgView];
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(inviteTapGesClick)];
    [inviteImgView addGestureRecognizer:tapGes];
    
    NewsCarouselView *newView = [[NewsCarouselView alloc] initWithFrame:CGRectMake(0, EndY(inviteImgView), WIDTH, 50*Scale) target:self];
    [self addSubview:newView];
    
    UIView *lineView = [UIToolsControl initViewWithFrame:CGRectMake(0, EndY(newView), WIDTH, 8*Scale) backgroundColor:THEMECOLOR_OF_GRAY];
    [self addSubview:lineView];
}
- (void)inviteTapGesClick {
    if (self.delegate && [self.delegate respondsToSelector:@selector(personalHomeHeaderViewNewInvitationTap)]) {
        [self.delegate personalHomeHeaderViewNewInvitationTap];
    }
}
- (void)newsCarouselViewTap:(ArticleItemModel *_Nullable)model {
    if (self.delegate && [self.delegate respondsToSelector:@selector(personalHomeHeaderViewNewCarouselTap:)]) {
        [self.delegate personalHomeHeaderViewNewCarouselTap:model];
    }
}

@end




/*
#import "PersonalHomeHeaderView.h"
#import "NewsCarouselView.h"

@interface PersonalHomeHeaderView () <NewsCarouselViewDelegate>

@end

@implementation PersonalHomeHeaderView

- (instancetype)initWithFrame:(CGRect)frame Target:(id)target {
    self = [super init];
    if (self) {
        [self initUI];
        self.delegate = target;
    }
    return self;
}
- (instancetype)initWithTarget:(id)target {
    self = [super init];
    if (self) {
        [self initUI];
        self.delegate = target;
    }
    return self;
}
- (void)initUI {
    PSCarouselView *carouselView = [[PSCarouselView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HomeBannerHeight) images:@[@"", @"", @""] space:0 bgImage:nil];
    [self addSubview:carouselView];
//    __weak typeof(self) weakSelf = self;
//    carouselView.tapImage = ^(BannerModel *model) {
    carouselView.tapImage = ^ {
        NSLog(@"轮播图Tap");
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(personalHomeHeaderViewBannerCarouselTap:)]) {
            [self.delegate personalHomeHeaderViewBannerCarouselTap:@"bannerTap"];
        }
    };
    
    
    UIImageView *inviteImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(20*Scale, EndY(carouselView), WIDTH-20*Scale, 125*Scale) imageName:@"home_invite_bg"];
    inviteImgView.userInteractionEnabled = YES;
    [self addSubview:inviteImgView];
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(inviteTapGesClick)];
    [inviteImgView addGestureRecognizer:tapGes];
    
    NewsCarouselView *newView = [[NewsCarouselView alloc] initWithFrame:CGRectMake(0, EndY(inviteImgView), WIDTH, 50*Scale) target:self];
    [self addSubview:newView];
    
    UIView *lineView = [UIToolsControl initViewWithFrame:CGRectMake(0, EndY(newView), WIDTH, 8*Scale) backgroundColor:THEMECOLOR_OF_GRAY];
    [self addSubview:lineView];
}
- (void)inviteTapGesClick {
    NSLog(@"dfsd");
}
- (void)newsCarouselViewTap {
    if (self.delegate && [self.delegate respondsToSelector:@selector(personalHomeHeaderViewNewCarouselTap)]) {
        [self.delegate personalHomeHeaderViewNewCarouselTap];
    }
}

@end

*/
